package wjx.database.view;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;

import wjx.database.bean.CodeThread;
import wjx.database.bean.StringUtil;
import wjx.database.jdbc.JDBCUtils;

public class MainFrm extends JFrame implements TreeSelectionListener {

	private JPanel contentPane, p1;
	private JTree tree = new JTree();
	private JSplitPane splitPane = new JSplitPane();
	private JTextField textInput1, textInput2;// 表定义输入文本
	private JTable table_show = new JTable();
	private JScrollPane scrollPane;
	private JComboBox combo;
	private JButton quitButton;
	private ResultSet rs;
	private String[][] data = null;
	private String[] tb = null;
	private Box box, box1, box2, box3, box4, box5, boxHead, boxPrint;

	private JLabel[] qLabel;// 查询属性标签组
	private JCheckBox[] qCheck;// 查询勾选组
	private String[] queryStr = null;
	private String[] queryType = null;
	private int tb_num;
	public static CodeThread myt;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrm frame = new MainFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainFrm() {
		
		myt = new CodeThread();
		myt.start();
		
		setVisible(true);
		setTitle("数据库管理系统");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 700, 500);
		splitPane.setDividerLocation(180);
		splitPane.setEnabled(false);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setResizable(false);
		JLabel label = new JLabel("====欢迎使用数据库管理系统====", JLabel.CENTER);
		label.setFont(new Font("Lucida Grande", 1, 20));
		splitPane.setRightComponent(label);

		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane
				.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addComponent(splitPane));
		gl_contentPane.setVerticalGroup(
				gl_contentPane.createParallelGroup(Alignment.LEADING).addComponent(splitPane, Alignment.TRAILING));

//		JTree tree = new JTree();
		tree.setShowsRootHandles(true);
		tree.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("功能菜单") {
			{
				DefaultMutableTreeNode node_1;
				this.add(new DefaultMutableTreeNode("表定义"));
				node_1 = new DefaultMutableTreeNode("数据维护");
				node_1.add(new DefaultMutableTreeNode("数据录入"));
				node_1.add(new DefaultMutableTreeNode("查询"));
				node_1.add(new DefaultMutableTreeNode("修改"));
				node_1.add(new DefaultMutableTreeNode("删除"));
				this.add(node_1);
				this.add(new DefaultMutableTreeNode("统计分析"));
			}
		}));
		splitPane.setLeftComponent(tree);

		// 实现树的点击监听
		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		tree.addTreeSelectionListener(this);

		contentPane.setLayout(gl_contentPane);
		this.setLocationRelativeTo(null);
		// 实现点击退出提示
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				int exi = JOptionPane.showConfirmDialog(null, "是否退出数据库管理系统？", "友情提示", JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE);
				if (exi == JOptionPane.YES_OPTION) {
					JOptionPane.showMessageDialog(null, "期待您的下次使用");
					System.exit(0);
				}
			}
		});

	}

	// 处理树节点点击事件
	@Override
	public void valueChanged(TreeSelectionEvent e) {
		DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
		if (selectionNode.isLeaf()) {
//			System.out.println(selectionNode.toString());
			if (selectionNode.toString() == "表定义") {// 实现新建表
				method1();
			}
			if (selectionNode.toString() == "数据录入") {// 实现表中添加数据
				method2();
			}
			if (selectionNode.toString() == "查询") {// 实现查询数据
				method3();
			}
			if (selectionNode.toString() == "修改") {// 实现修改表中数据
				method4();
			}
			if (selectionNode.toString() == "删除") {// 实现删除表
				method5();
			}
			if (selectionNode.toString() == "统计分析") {// 实现数据统计
				method6();
			}

		}

	}

	// 创建表 √
	private void method1() {
		JPanel p1 = new JPanel();
		JButton button1, button2;
		JLabel label = new JLabel("新建表", JLabel.CENTER);
		label.setFont(new Font("Lucida Grande", 1, 16));

		box = Box.createVerticalBox();
		boxHead = Box.createHorizontalBox();
		boxPrint = Box.createVerticalBox();

		boxHead.add(Box.createVerticalStrut(80));

		boxPrint.add(label);
		boxPrint.add(Box.createVerticalStrut(10));

		box1 = Box.createHorizontalBox();
		box4 = Box.createHorizontalBox();

		box2 = Box.createVerticalBox();// 垂直的盒子
		box3 = Box.createVerticalBox();

		box2.add(Box.createVerticalStrut(4));
		box2.add(new JLabel("表  名："));
		box2.add(Box.createHorizontalStrut(1));
		box2.add(Box.createVerticalStrut(2));
		box2.add(new JLabel("字段数："));
		box2.add(Box.createHorizontalStrut(1));

		textInput1 = new JTextField(10);
		box3.add(textInput1);
		box3.add(Box.createHorizontalStrut(1));
		textInput2 = new JTextField(10);
		box3.add(textInput2);
		box3.add(Box.createHorizontalStrut(1));

		button1 = new JButton("重  置");
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				resetValueActionperformed(e);
			}
		});
		button2 = new JButton("开始建表");
		button2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed(e);
			}
		});

		box4.add(button1);
		box4.add(Box.createHorizontalStrut(10));
		box4.add(button2);

		box.add(boxHead);
		box.add(boxPrint);
		box1.add(box2);
		box1.add(box3);
		box.add(box1);
		box.add(box4);

		p1.add(box);
		splitPane.setRightComponent(p1);
	}

	// 向表中添加数据 √
	private void method2() {
		p1 = new JPanel();
		JButton button;

		box = Box.createVerticalBox();
		boxHead = Box.createHorizontalBox();
		boxPrint = Box.createVerticalBox();
		boxHead.add(Box.createVerticalStrut(100));
		boxPrint.add(Box.createVerticalStrut(20));

		JLabel lb = new JLabel("从下拉框选择需要添加数据的表: ", JLabel.CENTER);
		lb.setFont(new Font("Lucida Grande", 1, 14));
		combo = new JComboBox();
		// 从下拉框获取表名
		List<String> tables = JDBCUtils.GetTableNames();
		String[] tbName = new String[tables.size()];
		String[] tbName_ = new String[tables.size() - 1];
		tables.toArray(tbName);
		for (int i = 0; i < tables.size() - 1; i++) {
			tbName_[i] = new String(tbName[i]);
		}
		combo.setModel(new DefaultComboBoxModel(tbName_));
		combo.setSelectedIndex(-1);
		box1 = Box.createHorizontalBox();
		box1.add(lb);
		box1.add(combo);
		button = new JButton("确定");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed1(e);
			}
		});

		box2 = Box.createHorizontalBox();
		box2.add(button);

		box.add(boxHead);
		box.add(boxPrint);
		box.add(Box.createHorizontalStrut(10));
		box.add(box1);
		box.add(box2);
		p1.add(box);
		splitPane.setRightComponent(p1);
	}

	private void confirmActionPerformed1(ActionEvent e) {
		if (combo.getSelectedItem() == null) {
			JOptionPane.showMessageDialog(null, "您还未选择要进行操作的表");
			return;
		}
		String name = combo.getSelectedItem().toString();

		new AddFrm(name).setVisible(true);
	}

	// 查询数据 √
	private void method3() {
		p1 = new JPanel();
		JButton button;

		box = Box.createVerticalBox();
		boxHead = Box.createHorizontalBox();
		boxPrint = Box.createVerticalBox();
		boxHead.add(Box.createVerticalStrut(100));
		boxPrint.add(Box.createVerticalStrut(20));

		JLabel lb = new JLabel("从下拉框选择想要查询的表: ", JLabel.CENTER);
		lb.setFont(new Font("Lucida Grande", 1, 14));
		combo = new JComboBox();
		// 从下拉框获取表名
		List<String> tables = JDBCUtils.GetTableNames();
		String[] tbName = new String[tables.size()];
		String[] tbName_ = new String[tables.size() - 1];
		tables.toArray(tbName);
		for (int i = 0; i < tables.size() - 1; i++) {
			tbName_[i] = new String(tbName[i]);
		}
		combo.setModel(new DefaultComboBoxModel(tbName_));
		combo.setSelectedIndex(-1);
		combo.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				selectQueryAction(combo.getSelectedItem().toString());
			}
		});

		box1 = Box.createHorizontalBox();
		box1.add(lb);
		box1.add(combo);
		button = new JButton("确定");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed2(e);
			}
		});

		box2 = Box.createVerticalBox();

		box5 = Box.createHorizontalBox();
		box5.add(button);

		box.add(boxHead);
		box.add(boxPrint);
		box.add(Box.createHorizontalStrut(10));
		box.add(box1);
		p1.add(box);
		splitPane.setRightComponent(p1);

	}

	private void selectQueryAction(String name) {
		splitPane.setRightComponent(p1);
		// 显示属性列
		// 获取表的所有属性列
		List<String> tableList = JDBCUtils.GetTableCol(name);
		int num = tableList.size();
//		String[] s = new String[tableList.size()] ;
		tb = new String[num];
		tableList.toArray(tb);
		JPanel jp = new JPanel();
//		JPanel lay = new JPanel() ;
//		lay.setPreferredSize(new Dimension(200,100));
		JScrollPane scro = new JScrollPane(jp);
		scro.setViewportView(jp);
//		scro.setToolTipText("选择想要显示的属性列");
//		jp.setPreferredSize(new Dimension(200,200));
		scro.setPreferredSize(new Dimension(200, 100));
		scro.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

		qLabel = new JLabel[num + 1];
		qCheck = new JCheckBox[num + 1];

		box2.removeAll();
		Box boxShow = Box.createHorizontalBox();
		boxShow.add(new JLabel("勾选想要显示的属性列"));
		box2.add(boxShow);

		for (int i = 0; i < num; i++) {
			boxShow = Box.createHorizontalBox();
			qLabel[i] = new JLabel(tb[i]);
			boxShow.add(qLabel[i]);
			qCheck[i] = new JCheckBox("");
			boxShow.add(qCheck[i]);
			box2.add(boxShow);
		}
		qLabel[num] = new JLabel("全选");
		qCheck[num] = new JCheckBox("");
		boxShow = Box.createHorizontalBox();
		boxShow.add(qLabel[num]);
		boxShow.add(qCheck[num]);

		jp.add(box2);
		Box bx = Box.createHorizontalBox();
		bx.add(scro);

		box.removeAll();
		box.add(boxHead);
		box.add(boxPrint);
		box.add(Box.createHorizontalStrut(10));
		box.add(box1);
		box.add(bx);
		box.add(boxShow);
		box.add(box5);
		p1.remove(box);
		p1.add(box);
	}

	private void confirmActionPerformed2(ActionEvent e) {
		List<String> nameList = new ArrayList<>();
		int num = qLabel.length;
		List<String> queryList = JDBCUtils.GetTableColAnd(combo.getSelectedItem().toString());
		String[] mid = new String[queryList.size()];
		queryList.toArray(mid);
		if (qCheck[num - 1].isSelected()) {
			queryStr = new String[queryList.size() / 2];
			queryType = new String[queryList.size() / 2];
			queryList.toArray(mid);
			for (int i = 0; i < queryList.size() / 2; i++) {
				queryStr[i] = mid[2 * i];
				queryType[i] = mid[2 * i + 1];
			}
			nameList.add(combo.getSelectedItem().toString());
			new QueryFrm(combo.getSelectedItem().toString(), queryStr, queryType, 1).setVisible(true);
			return;
		}
		// TODO 新开一个条件查询窗口
		for (int i = 0; i < num - 1; i++) {
			if (qCheck[i].isSelected()) {
				nameList.add(qLabel[i].getText());
				System.out.println("**" + nameList.get(0));
			}
		}
		queryStr = new String[nameList.size()];
		queryType = new String[nameList.size()];
		for (int i = 0, j = 0; i < num - 1; i++) {
			if (qCheck[i].isSelected()) {
				queryStr[j] = qLabel[i].getText();
				queryType[j] = mid[2 * i + 1];
				j++;
			}
		}
		if (nameList.size() == 0) {
			JOptionPane.showMessageDialog(null, "请至少选择一个属性列以供显示");
			return;
		}
		String name = combo.getSelectedItem().toString();

		new QueryFrm(combo.getSelectedItem().toString(), queryStr, queryType, 0).setVisible(true);
	}

	// 修改表中数据
	// TODO 修改部分

	// 修改数据 √
	private void method4() {
		p1 = new JPanel();
		JButton button1, button2;

		box = Box.createVerticalBox();
		boxHead = Box.createHorizontalBox();
		boxPrint = Box.createVerticalBox();
		boxHead.add(Box.createVerticalStrut(100));
		boxPrint.add(Box.createVerticalStrut(20));

		JLabel lb = new JLabel("从下拉框选择需要修改的表:", JLabel.CENTER);
		lb.setFont(new Font("Lucida Grande", 1, 14));
		combo = new JComboBox();
		// 从下拉框获取表名
		List<String> tables = JDBCUtils.GetTableNames();
		String[] tbName = new String[tables.size()];
		String[] tbName_ = new String[tables.size() - 1];
//		System.out.println(tables.size()) ;
		tables.toArray(tbName);
		for (int i = 0; i < tables.size() - 1; i++) {
			tbName_[i] = new String(tbName[i]);
		}
		combo.setModel(new DefaultComboBoxModel(tbName_));
		combo.setSelectedIndex(-1);
		box1 = Box.createHorizontalBox();
		box1.add(lb);
		box1.add(combo);

		JButton button = new JButton("确定");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed3(e);
			}
		});
		box2 = Box.createHorizontalBox();
		box2.add(button);

		box.add(boxHead);
		box.add(boxPrint);
		box.add(Box.createHorizontalStrut(10));
		box.add(box1);
		box.add(box2);
		p1.add(box);
		splitPane.setRightComponent(p1);
	}

	private void confirmActionPerformed3(ActionEvent e) {
		if (combo.getSelectedItem() == null) {
			JOptionPane.showMessageDialog(null, "您还未选择要进行操作的表");
			return;
		}
		if (combo.getSelectedItem().toString().equals("t_user")) {
			JOptionPane.showMessageDialog(null, "抱歉！您没有权限编辑该表！");
			return;
		}
		// 修改数据窗口
		new EditFrm(combo.getSelectedItem().toString()).setVisible(true);
	}

	// 删除表数据
	private void method5() {
		p1 = new JPanel();
		JButton button1, button2;

		box = Box.createVerticalBox();
		boxHead = Box.createHorizontalBox();
		boxPrint = Box.createVerticalBox();
		boxHead.add(Box.createVerticalStrut(100));
		boxPrint.add(Box.createVerticalStrut(20));

		JLabel lb = new JLabel("从下拉框选择想要删除的表:", JLabel.CENTER);
		lb.setFont(new Font("Lucida Grande", 1, 14));
		combo = new JComboBox();
		// 从下拉框获取表名
		List<String> tables = JDBCUtils.GetTableNames();
		String[] tbName = new String[tables.size()];
		String[] tbName_ = new String[tables.size() - 1];
//		System.out.println(tables.size()) ;
		tables.toArray(tbName);
		for (int i = 0; i < tables.size() - 1; i++) {
			tbName_[i] = new String(tbName[i]);
		}
		combo.setModel(new DefaultComboBoxModel(tbName_));
		combo.setSelectedIndex(-1);
		combo.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				selectDeleteAction(combo.getSelectedItem().toString());
			}
		});
		box1 = Box.createHorizontalBox();
		box1.add(lb);
		box1.add(combo);

		box2 = Box.createHorizontalBox();

		JButton button = new JButton("删除整张表格");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed4(e);
			}
		});
		box2.add(button);

		button = new JButton("删除所选属性列");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed6(e);
			}
		});
		box2.add(button);

		button = new JButton("仅删除表格数据");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				confirmActionPerformed5(e);
			}
		});
		box2.add(button);
		box4 = Box.createHorizontalBox();

		box.add(boxHead);
		box.add(boxPrint);
		box.add(Box.createHorizontalStrut(10));
		box.add(box1);
		box.add(Box.createHorizontalStrut(8));
		box.add(box2);
		box.add(box4);
		p1.add(box);
		splitPane.setRightComponent(p1);
	}

	// 删除属性列

	private void confirmActionPerformed6(ActionEvent e) {
		if (combo.getSelectedItem() == null) {
			JOptionPane.showMessageDialog(null, "您还未选择要进行操作的表");
			return;
		}
		String nm = combo.getSelectedItem().toString();
		if (!StringUtil.isHere(nm, JDBCUtils.GetTableNames())) {
			JOptionPane.showMessageDialog(null, "该表已删除！");
			return;
		}

		if (nm.equals("t_user")) {
			JOptionPane.showMessageDialog(null, "抱歉！您没有权限删除该表的任何属性列！");
			return;
		}

		List<String> primaryK = new ArrayList<>();
		primaryK = JDBCUtils.GetPriKey(nm);
		int len = primaryK.size();
		int cntPri = 0;
		String[] ns = new String[len];
		primaryK.toArray(ns);

		// 删除所选属性列
		String sql = "alter table databaseManager." + nm + " drop column ";
		// 构建alter语句
		int cnt = 0;
		nm = "";
		for (int i = 0; i < qLabel.length; i++) {
			if (qCheck[i].isSelected()) {
				if (!StringUtil.isHere(qLabel[i].getText(),
						JDBCUtils.GetTableCol(combo.getSelectedItem().toString()))) {
					JOptionPane.showMessageDialog(null, "该列已被删除！");
					return;
				}
				if (StringUtil.isHere(qLabel[i].getText(), primaryK)) {
					JOptionPane.showMessageDialog(null, "抱歉！您不可以删除主键列！");
					return;
				}
				if (cnt > 0) {
					sql += ',';
					nm += ',';
				}
				sql += qLabel[i].getText();
				cnt++;
				nm += qLabel[i].getText();
			}
		}
		System.out.println(sql);
		if (cnt == 0) {
			JOptionPane.showMessageDialog(null, "您还未选择想要删除的属性列！");
			return;
		}

		int result = JOptionPane.showConfirmDialog(null, "确认删除所选属性列？", "删除属性列" + nm, JOptionPane.YES_NO_OPTION);
		// 退出窗口
		if (result == JOptionPane.YES_NO_OPTION) {
			// TODO 删除整张表格
			int res = -1;
			try {
				res = JDBCUtils.update(sql);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			if (res >= 0)
				JOptionPane.showMessageDialog(null, "列" + nm + "删除成功");
			else
				JOptionPane.showMessageDialog(null, "列" + nm + "删除失败");
		}

	}

	private void selectDeleteAction(String name) {
		// 显示可选的删除的列
		splitPane.setRightComponent(p1);
		// 显示属性列
		// 获取表的所有属性列
		List<String> tableList = JDBCUtils.GetTableCol(name);
		int num = tableList.size();
		tb = new String[num];
		tableList.toArray(tb);
		JPanel jp = new JPanel();

		JScrollPane scro = new JScrollPane(jp);
		scro.setViewportView(jp);
		scro.setPreferredSize(new Dimension(200, 100));
		scro.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

		qLabel = new JLabel[num];
		qCheck = new JCheckBox[num];

		box.remove(box4);
		box5 = Box.createVerticalBox();
		Box boxShow = Box.createHorizontalBox();
		boxShow.add(new JLabel("请勾选想要删除的属性列"));
		box5.add(boxShow);

		for (int i = 0; i < num; i++) {
			boxShow = Box.createHorizontalBox();
			qLabel[i] = new JLabel(tb[i]);
			boxShow.add(qLabel[i]);
			qCheck[i] = new JCheckBox("");
			boxShow.add(qCheck[i]);
			box5.add(boxShow);
		}

		jp.add(box5);
		box4 = Box.createHorizontalBox();
		box4.add(scro);

		box.add(box4);
		p1.add(box);

	}

	// 删除整张表
	private void confirmActionPerformed4(ActionEvent e) {
		if (combo.getSelectedItem() == null) {
			JOptionPane.showMessageDialog(null, "您还未选择要进行操作的表");
			return;
		}
		String tNm = combo.getSelectedItem().toString();
		if (!StringUtil.isHere(tNm, JDBCUtils.GetTableNames())) {
			JOptionPane.showMessageDialog(null, "该表已删除！");
			return;
		}
		if (tNm.equals("t_user")) {
			JOptionPane.showMessageDialog(null, "抱歉！您没有权限删除该表！");
			return;
		}
		int result = JOptionPane.showConfirmDialog(null, "确认删除整张表？", "删除表" + tNm, JOptionPane.YES_NO_OPTION);
		// 退出窗口
		if (result == JOptionPane.YES_NO_OPTION) {
			// TODO 删除整张表格
			int res = -1;
			String sql = "drop table databaseManager." + tNm;
			try {
				res = JDBCUtils.update(sql);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			if (res >= 0)
				JOptionPane.showMessageDialog(null, "表" + tNm + "删除成功");
			else
				JOptionPane.showMessageDialog(null, "表" + tNm + "删除失败");
		}

	}
	// 新开一个界面进行删除

	private void confirmActionPerformed5(ActionEvent e) {
		if (combo.getSelectedItem() == null) {
			JOptionPane.showMessageDialog(null, "您还未选择要进行操作的表");
			return;
		}
		String tNm = combo.getSelectedItem().toString();
		if (!StringUtil.isHere(tNm, JDBCUtils.GetTableNames())) {
			JOptionPane.showMessageDialog(null, "该表已删除！");
			return;
		}
		if (tNm.equals("t_user")) {
			JOptionPane.showMessageDialog(null, "抱歉！您没有权限删除该表！");
			return;
		}
		// 新开一个窗口
		new DeleteFrm(combo.getSelectedItem().toString()).setVisible(true);
	}

	// 实现数据统计
	private void method6() {

	}

	private void confirmActionPerformed(ActionEvent e) {
		String table = this.textInput1.getText();
		String number = this.textInput2.getText();
		if (StringUtil.isEmpty(table)) {
			JOptionPane.showMessageDialog(null, "表名不能为空！");
			return;
		}
		if (StringUtil.isEmpty(number)) {
			JOptionPane.showMessageDialog(null, "字段数不能为空！");
			return;
		}
		if (StringUtil.isHere(table, JDBCUtils.GetTableNames())) {
			JOptionPane.showMessageDialog(null, "对不起，该表已存在，请重新命名！");
			return;
		}
		try {
			int num = Integer.parseInt(this.textInput2.getText());
			new CreateTableFrm(table, num).setVisible(true);
		} catch (RuntimeException e2) {
			e2.printStackTrace();
			JOptionPane.showMessageDialog(null, "请在字段数输入一个数字！");
			return;
		}
	}

	private void resetValueActionperformed(ActionEvent e) {
		// 重置表定义输入文本
		this.textInput1.setText("");
		this.textInput2.setText("");
	}
}
